package com.gblfy.wx.h5.controller;

import com.gblfy.wx.h5.vo.ResponseDto;
import com.gblfy.wx.h5.service.FileHandleService;
import com.gblfy.wx.h5.vo.FileVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

@RestController
public class FileHandleController {

    public static final String BUSINESS_NAME = "文件上传";
    @Autowired
    private FileHandleService fileHandleService;

    /**
     * 单/多文件上传
     *
     * @param files
     * @return
     * @throws Exception
     */
    @PostMapping("/multipleFilesUpload")
    public ResponseDto uploadFile(@RequestParam MultipartFile[] files) throws Exception {
        List<FileVo> fileVoList = new ArrayList<>();
        for (MultipartFile file : files) {
            FileVo fileVo = fileHandleService.uploadChild(file);
            fileVoList.add(fileVo);
        }
        ResponseDto responseDto = new ResponseDto();
        responseDto.setContent(fileVoList);
        return responseDto;
    }

    /**
     * 删除指定文件
     *
     * @param fileVo
     * @return
     * @throws Exception
     */
    @PostMapping("/delSpeciFiedFile")
    public ResponseDto delSpeciFiedFile(@RequestBody FileVo fileVo) throws Exception {
        fileHandleService.delSpeciFiedFile(fileVo.getHandleFileName(), fileVo.getFileBelongCategory(),fileVo.getPicNumber());
        ResponseDto responseDto = new ResponseDto();
        responseDto.setContent("");
        return responseDto;
    }
}
